const AbsCommand = require('./AbsCommand');
const webContentUtil = require('../utils/webContentUtil');
const dialogUtil = require('../utils/dialogUtil');
const fileUtil = require('../utils/fileUtil');
const designFileUtil = require('../utils/designFileUtil');

class OpenFileCommand extends AbsCommand {

  async execute() {
    const filePath = await dialogUtil.showOpen({
      title: '打开文件',
      filters: [{
        name: '页面配置文件',
        extensions: ['page']
      }]
    });

    const design = await designFileUtil.open(filePath);
    const filename = fileUtil.filename(filePath);
    webContentUtil.getMainWebContent().send('open-file', design, filename);
  }
}

module.exports = OpenFileCommand;
